﻿@model IEnumerable<Von.Web.Models.WebServiceBase>
@{
    ViewData["Title"] = "系统服务管理";
}
<h2>系统服务</h2>
<table id="ServiceList" class="table">
    <thead>
        <tr>
            <th>服务名称</th>
            <th>间隔方式</th>
            <th>间隔值</th>
            <th>必要性</th>
            <th>状态</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.ServiceName)</td>
                <td>@Html.DisplayFor(modelItem => item.InterKind)</td>
                <td>@Html.DisplayFor(modelItem => item.Intervalue)</td>
                <td>@Html.DisplayFor(modelItem => item.Necessary)</td>
                <td>@Html.DisplayFor(modelItem => item.Status)</td>
                <td>
                    <input type="button" class="btn-link" onclick="EditService(this, '@item.ID')" value="编辑">
                </td>
            </tr>
        }
    </tbody>
</table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="ServiceEditor" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" data-mode="new">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color:aquamarine;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">系统服务编辑</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <label for="ServiceName" class="input-group-addon column-prompt">服务名称</label>
                    <input id="ServiceName" class="form-control" />
                </div>
                <div class="input-group">
                    <label for="InterKind" class="input-group-addon column-prompt">间隔方式</label>
                    <select id="InterKind" class="form-control">
                        <option value="0">毫秒</option>
                        <option value="1">秒</option>
                        <option value="2">分</option>
                        <option value="3">时</option>
                        <option value="4">日</option>
                        <option value="5">周</option>
                        <option value="6">月</option>
                        <option value="7">年</option>
                    </select>
                </div>
                <div class="input-group">
                    <label for="Intervalue" class="input-group-addon column-prompt">间隔值</label>
                    <input id="Intervalue" type="number" class="form-control" />
                </div>
                <div class="input-group">
                    <label class="input-group-addon column-prompt"><input id="Necessary" type="checkbox" /></label>
                    <label for="Necessary" class="form-control">必要性</label>
                </div>
                <div class="input-group">
                    <label for="Status" class="input-group-addon column-prompt">状态</label>
                    <select id="Status" class="form-control">
                        <option>注册</option>
                        <option>启用</option>
                        <option>禁用</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="Param" class="control-label">服务参数</label>
                    <textarea id="Param" class="form-control" style="width:100%;"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="ID" />
                <div class="form-group">
                    <input value="保存" class="btn btn-default" onclick="SaveService()" />
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<script type="text/javascript">
    function EditService(btn, id) {
        von.selectRow(btn);
        AjaxPostData("@Url.Ajax("GetByService")", { ID: id }, function (data) {
            von.editor.setData(data);
            von.editor.display("edit");
        });
    }
    function CheckService(){
        var msg = "";
        if($("#ServiceName").val() == "") msg += "名称必须录入，不允许为空。";
        return msg;
    }
    function SaveService() {
        var msg = CheckService();
        if (msg != "") return SysWarning(msg);
        var data = {};
        von.editor.getData(data);
        data.Necessary = $("#Necessary").prop("checked");
        AjaxPostData("@Url.Ajax("SaveService")", data, function (data) { von.replaceRow(von.getHtml(data)); von.editor.close(); });
    }
</script>
@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "ServiceInit",
    @<script>
        var von = VonGrid({
            app: "Service",
            keyName: "ID",
            displayFields: ["ServiceName","InterKind","Intervalue","Necessary","Status"],
            fields: ["ID", "ServiceName", "InterKind", "Intervalue", "Necessary", "Status", "Param"],
            onAddFields: function (data) {
                von.addCell(data.ServiceName);
                switch (data.InterKind) {
                    case 0: von.addCell("毫秒"); break;
                    case 1: von.addCell("秒");break;
                    case 2: von.addCell("分");break;
                    case 3: von.addCell("时");break;
                    case 4: von.addCell("日");break;
                    case 5: von.addCell("周");break;
                    case 6: von.addCell("月");break;
                    case 7: von.addCell("年");break;
                }
                von.addCell(data.Intervalue);
                von.addCell(data.Necessary);
                von.addCell(data.Status);
            },
            onAddBtns: function (data) { von.addLink(data.ID, "Edit" + von.app, "编辑");}
        });
    </script>
)
